/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Comparator.java
 *
 * Created on Nov 10, 2010, 3:04:46 PM
 */

package UserInterface.AnnotationCompare;

import ResultEditor.Annotations.Annotation;
import ResultEditor.Annotations.ComplexRelationship;
import ResultEditor.Annotations.Depot;
import ResultEditor.Annotations.NormalRelationship;
import ResultEditor.Annotations.eComplex;
import ResultEditor.SelectedAnnotationView.iListCellRenderer;
import ResultEditor.SelectedAnnotationView.iListEntry;
import java.awt.Color;
import java.awt.Cursor;
import java.util.Vector;
import javax.swing.JList;
import javax.swing.JTextPane;

/**
 *
 * @author leng
 */
public class Comparator extends javax.swing.JPanel {

    protected UserInterface.GUI gui;
    protected UserInterface.AnnotationCompare.ExpandButton controlButton;
    protected JTextPane textPaneforClinicalNotes;

    /** Creates new form Comparator */
    public Comparator(UserInterface.GUI gui, UserInterface.AnnotationCompare.ExpandButton controlButton,
            JTextPane textPaneforClinicalNotes) {
        this.gui = gui;
        this.controlButton = controlButton;
        initComponents();

        // set cursor
        jButton4.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        jButton5.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        jButton10.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        jButton11.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        
        // hide some buttons
        jButton_SelectClass.setVisible(false);
        jButton_relationships.setVisible(false);
        jButton_relationships1.setVisible(false);
        this.textPaneforClinicalNotes = textPaneforClinicalNotes;
    }


    /**Flags which used to show differences between 2 annotations,
     * one annotation is the primary annotaiton, the other one is
     * the annotation user just selected from the annotations list
     * on comparator panel;
     */
    private static class flags_of_differences{
        static boolean isDifference_inText = false;
        static boolean isDifference_inSpan = false;
        static boolean isDifference_inClass = false;
        static boolean isDifference_inComment = false;
        static boolean isDifference_inAnnotator = false;
        static boolean isDifference_inNormalRelationship = false;
        static boolean isDifference_inComplexRelationship = false;

        /**set all flags to false: means there is no any difference
         * between these two annotations.
         */
        public static void setAlltoFalse(){
            isDifference_inText = false;
            isDifference_inSpan = false;
            isDifference_inClass = false;
            isDifference_inComment = false;
            isDifference_inAnnotator = false;
            isDifference_inNormalRelationship = false;
            isDifference_inComplexRelationship = false;
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel40 = new javax.swing.JPanel();
        jPanel_colorfulTextBar_filebrowser3 = new javax.swing.JPanel();
        jLabel27 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jPanel42 = new javax.swing.JPanel();
        jToolBar4 = new javax.swing.JToolBar();
        jLabel23 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel43 = new javax.swing.JPanel();
        jToolBar5 = new javax.swing.JToolBar();
        jLabel_toolbar_split = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jPanel41 = new javax.swing.JPanel();
        jPanel_multipleResultShowList = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jList_selectedAnnotations = new javax.swing.JList();
        jPanel45 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jPanel50 = new javax.swing.JPanel();
        jPanel74 = new javax.swing.JPanel();
        jPanel_annotation_details = new javax.swing.JPanel();
        jPanel64 = new javax.swing.JPanel();
        jPanel65 = new javax.swing.JPanel();
        jPanel55 = new javax.swing.JPanel();
        jLabel17 = new javax.swing.JLabel();
        jPanel39 = new javax.swing.JPanel();
        jTextField_spanLocation = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jPanel44 = new javax.swing.JPanel();
        jTextField_annotationClassnames = new javax.swing.JTextField();
        jButton_SelectClass = new javax.swing.JButton();
        jLabel38 = new javax.swing.JLabel();
        jPanel66 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea_comment = new javax.swing.JTextArea();
        jSplitPane5 = new javax.swing.JSplitPane();
        jPanel48 = new javax.swing.JPanel();
        jPanel70 = new javax.swing.JPanel();
        jPanel61 = new javax.swing.JPanel();
        jButton_relationships = new javax.swing.JButton();
        jLabel39 = new javax.swing.JLabel();
        jScrollPane8 = new javax.swing.JScrollPane();
        jList_complexrelationships = new javax.swing.JList();
        jPanel71 = new javax.swing.JPanel();
        jScrollPane9 = new javax.swing.JScrollPane();
        jList_normalrelationship = new javax.swing.JList();
        jPanel63 = new javax.swing.JPanel();
        jButton_relationships1 = new javax.swing.JButton();
        jLabel40 = new javax.swing.JLabel();
        jPanel75 = new javax.swing.JPanel();
        jPanel76 = new javax.swing.JPanel();
        jLabel37 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        jTextField_creationdate = new javax.swing.JTextField();
        jTextField_annotator = new javax.swing.JTextField();
        jPanel87 = new javax.swing.JPanel();
        jPanel84 = new javax.swing.JPanel();
        jPanel68 = new javax.swing.JPanel();
        jPanel_colorfulTextBar_filebrowser4 = new javax.swing.JPanel();
        jPanel69 = new javax.swing.JPanel();
        jPanel72 = new javax.swing.JPanel();
        jLabel41 = new javax.swing.JLabel();
        jScrollPane10 = new javax.swing.JScrollPane();
        jList3 = new javax.swing.JList();
        jPanel_colorfulTextBar_filebrowser7 = new javax.swing.JPanel();

        setMinimumSize(new java.awt.Dimension(0, 0));
        setLayout(new java.awt.BorderLayout());

        jPanel40.setBackground(new java.awt.Color(236, 233, 216));
        jPanel40.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel40.setPreferredSize(new java.awt.Dimension(390, 238));
        jPanel40.setLayout(new java.awt.BorderLayout());

        jPanel_colorfulTextBar_filebrowser3.setBackground(new java.awt.Color(41, 119, 167));
        jPanel_colorfulTextBar_filebrowser3.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel_colorfulTextBar_filebrowser3.setLayout(new java.awt.BorderLayout());

        jLabel27.setBackground(new java.awt.Color(41, 119, 167));
        jLabel27.setFont(new java.awt.Font("Calibri", 1, 13));
        jLabel27.setForeground(new java.awt.Color(255, 255, 255));
        jLabel27.setText("  COMPARATOR");
        jLabel27.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jLabel27.setMaximumSize(new java.awt.Dimension(5000, 19));
        jLabel27.setPreferredSize(new java.awt.Dimension(200, 19));
        jLabel27.setRequestFocusEnabled(false);
        jLabel27.setVerifyInputWhenFocusTarget(false);
        jPanel_colorfulTextBar_filebrowser3.add(jLabel27, java.awt.BorderLayout.NORTH);

        jPanel1.setLayout(new java.awt.BorderLayout());

        jPanel42.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel42.setLayout(new java.awt.BorderLayout());

        jToolBar4.setBackground(new java.awt.Color(237, 237, 237));
        jToolBar4.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jToolBar4.setFloatable(false);
        jToolBar4.setBorderPainted(false);
        jToolBar4.setFocusable(false);
        jToolBar4.setMinimumSize(new java.awt.Dimension(0, 0));
        jToolBar4.setRequestFocusEnabled(false);
        jToolBar4.setVerifyInputWhenFocusTarget(false);

        jLabel23.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/breakermono.png"))); // NOI18N
        jLabel23.setOpaque(true);
        jToolBar4.add(jLabel23);

        jButton1.setFont(new java.awt.Font("Calibri", 0, 14));
        jButton1.setText("Accept");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setMaximumSize(new java.awt.Dimension(52, 24));
        jButton1.setMinimumSize(new java.awt.Dimension(0, 0));
        jButton1.setPreferredSize(new java.awt.Dimension(52, 24));
        jButton1.setSize(new java.awt.Dimension(60, 26));
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar4.add(jButton1);

        jButton2.setFont(new java.awt.Font("Calibri", 0, 14));
        jButton2.setText("Reject");
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setMaximumSize(new java.awt.Dimension(52, 24));
        jButton2.setMinimumSize(new java.awt.Dimension(0, 0));
        jButton2.setPreferredSize(new java.awt.Dimension(52, 24));
        jButton2.setSize(new java.awt.Dimension(60, 26));
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jToolBar4.add(jButton2);

        jButton3.setFont(new java.awt.Font("Calibri", 0, 14));
        jButton3.setText("Ignore");
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton3.setMaximumSize(new java.awt.Dimension(52, 24));
        jButton3.setMinimumSize(new java.awt.Dimension(0, 0));
        jButton3.setPreferredSize(new java.awt.Dimension(52, 24));
        jButton3.setSize(new java.awt.Dimension(60, 26));
        jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jToolBar4.add(jButton3);

        jPanel42.add(jToolBar4, java.awt.BorderLayout.CENTER);

        jPanel1.add(jPanel42, java.awt.BorderLayout.SOUTH);

        jPanel43.setLayout(new java.awt.BorderLayout());

        jToolBar5.setBackground(new java.awt.Color(237, 237, 237));
        jToolBar5.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jToolBar5.setFloatable(false);
        jToolBar5.setBorderPainted(false);
        jToolBar5.setFocusable(false);
        jToolBar5.setRequestFocusEnabled(false);
        jToolBar5.setVerifyInputWhenFocusTarget(false);

        jLabel_toolbar_split.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/breakermono.png"))); // NOI18N
        jLabel_toolbar_split.setOpaque(true);
        jToolBar5.add(jLabel_toolbar_split);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/span_ll.png"))); // NOI18N
        jButton4.setToolTipText("<html>Move the start of the annotation<br>One character to the left.<br>Hotkey(Ctrl + Left Arrow)</html>");
        jButton4.setBorderPainted(false);
        jButton4.setContentAreaFilled(false);
        jButton4.setMaximumSize(new java.awt.Dimension(28, 23));
        jButton4.setMinimumSize(new java.awt.Dimension(1, 1));
        jButton4.setPreferredSize(new java.awt.Dimension(23, 23));
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jToolBar5.add(jButton4);

        jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/span_lr.png"))); // NOI18N
        jButton10.setToolTipText("<html>Move the start of the annotation<br>One character to the right.<br>Hotkey(Ctrl + Right Arrow)</html>");
        jButton10.setBorderPainted(false);
        jButton10.setContentAreaFilled(false);
        jButton10.setMaximumSize(new java.awt.Dimension(28, 23));
        jButton10.setMinimumSize(new java.awt.Dimension(1, 1));
        jButton10.setPreferredSize(new java.awt.Dimension(23, 23));
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });
        jToolBar5.add(jButton10);

        jButton11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/span_rl.png"))); // NOI18N
        jButton11.setToolTipText("<html>Move the end of the annotation<br>One character to the left.<br>Hotkey(Alt + Left Arrow)</html>");
        jButton11.setBorderPainted(false);
        jButton11.setContentAreaFilled(false);
        jButton11.setMaximumSize(new java.awt.Dimension(28, 23));
        jButton11.setMinimumSize(new java.awt.Dimension(1, 1));
        jButton11.setPreferredSize(new java.awt.Dimension(23, 23));
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });
        jToolBar5.add(jButton11);

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/span_rr.png"))); // NOI18N
        jButton5.setToolTipText("<html>Move the end of the annotation<br>One character to the right.<br>Hotkey(Alt + Right Arrow)</html>");
        jButton5.setBorderPainted(false);
        jButton5.setContentAreaFilled(false);
        jButton5.setMaximumSize(new java.awt.Dimension(28, 23));
        jButton5.setMinimumSize(new java.awt.Dimension(1, 1));
        jButton5.setPreferredSize(new java.awt.Dimension(23, 23));
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jToolBar5.add(jButton5);

        jPanel43.add(jToolBar5, java.awt.BorderLayout.CENTER);

        jPanel1.add(jPanel43, java.awt.BorderLayout.NORTH);

        jPanel_colorfulTextBar_filebrowser3.add(jPanel1, java.awt.BorderLayout.CENTER);

        jPanel40.add(jPanel_colorfulTextBar_filebrowser3, java.awt.BorderLayout.NORTH);

        jPanel41.setMaximumSize(new java.awt.Dimension(32767, 280));
        jPanel41.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel41.setLayout(new java.awt.GridLayout(1, 2, 4, 2));

        jPanel_multipleResultShowList.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(240, 240, 240), 3));
        jPanel_multipleResultShowList.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel_multipleResultShowList.setLayout(new java.awt.BorderLayout());

        jScrollPane5.setBorder(null);
        jScrollPane5.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane5.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane5.setMinimumSize(new java.awt.Dimension(0, 0));

        jList_selectedAnnotations.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jList_selectedAnnotations.setFont(new java.awt.Font("Calibri", 0, 11));
        jList_selectedAnnotations.setSelectionBackground(new java.awt.Color(74, 136, 218));
        jList_selectedAnnotations.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jList_selectedAnnotationsValueChanged(evt);
            }
        });
        jScrollPane5.setViewportView(jList_selectedAnnotations);

        jPanel_multipleResultShowList.add(jScrollPane5, java.awt.BorderLayout.CENTER);

        jPanel45.setBackground(new java.awt.Color(237, 237, 237));

        jLabel12.setBackground(new java.awt.Color(236, 233, 216));
        jLabel12.setFont(new java.awt.Font("Calibri", 1, 13));
        jLabel12.setForeground(new java.awt.Color(102, 102, 102));
        jLabel12.setText("Alternative Annotations:");
        jLabel12.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel12.setMaximumSize(new java.awt.Dimension(0, 25));
        jLabel12.setRequestFocusEnabled(false);
        jLabel12.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        org.jdesktop.layout.GroupLayout jPanel45Layout = new org.jdesktop.layout.GroupLayout(jPanel45);
        jPanel45.setLayout(jPanel45Layout);
        jPanel45Layout.setHorizontalGroup(
            jPanel45Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel45Layout.createSequentialGroup()
                .add(jLabel12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 203, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel45Layout.setVerticalGroup(
            jPanel45Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jLabel12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );

        jPanel_multipleResultShowList.add(jPanel45, java.awt.BorderLayout.NORTH);

        jPanel50.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel50.setLayout(new java.awt.GridLayout(2, 0, 0, 2));

        jPanel74.setLayout(new java.awt.BorderLayout());
        jPanel50.add(jPanel74);

        jPanel_multipleResultShowList.add(jPanel50, java.awt.BorderLayout.SOUTH);

        jPanel41.add(jPanel_multipleResultShowList);

        jPanel_annotation_details.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(240, 240, 240), 2));
        jPanel_annotation_details.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel_annotation_details.setLayout(new java.awt.BorderLayout());

        org.jdesktop.layout.GroupLayout jPanel64Layout = new org.jdesktop.layout.GroupLayout(jPanel64);
        jPanel64.setLayout(jPanel64Layout);
        jPanel64Layout.setHorizontalGroup(
            jPanel64Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 225, Short.MAX_VALUE)
        );
        jPanel64Layout.setVerticalGroup(
            jPanel64Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 0, Short.MAX_VALUE)
        );

        jPanel_annotation_details.add(jPanel64, java.awt.BorderLayout.NORTH);

        jPanel65.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel65.setLayout(new java.awt.BorderLayout());

        jPanel55.setBackground(new java.awt.Color(237, 237, 237));
        jPanel55.setMaximumSize(new java.awt.Dimension(2147483647, 103));
        jPanel55.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel55.setPreferredSize(new java.awt.Dimension(0, 103));
        jPanel55.setLayout(new java.awt.BorderLayout());

        jLabel17.setBackground(new java.awt.Color(236, 233, 216));
        jLabel17.setFont(new java.awt.Font("Calibri", 0, 13));
        jLabel17.setForeground(new java.awt.Color(153, 153, 153));
        jLabel17.setText("Span:");
        jLabel17.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel17.setMaximumSize(new java.awt.Dimension(0, 25));
        jLabel17.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel55.add(jLabel17, java.awt.BorderLayout.NORTH);

        jPanel39.setBackground(new java.awt.Color(237, 237, 237));
        jPanel39.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(240, 240, 240), 2));
        jPanel39.setMaximumSize(new java.awt.Dimension(32767, 112));
        jPanel39.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel39.setPreferredSize(new java.awt.Dimension(106, 132));
        jPanel39.setLayout(new java.awt.GridLayout(4, 0, 0, 2));

        jTextField_spanLocation.setFont(new java.awt.Font("Calibri", 0, 13));
        jTextField_spanLocation.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jTextField_spanLocation.setMaximumSize(null);
        jTextField_spanLocation.setMinimumSize(new java.awt.Dimension(0, 0));
        jTextField_spanLocation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField_spanLocationActionPerformed(evt);
            }
        });
        jPanel39.add(jTextField_spanLocation);

        jLabel16.setBackground(new java.awt.Color(236, 233, 216));
        jLabel16.setFont(new java.awt.Font("Calibri", 0, 13));
        jLabel16.setForeground(new java.awt.Color(153, 153, 153));
        jLabel16.setText("Markable:");
        jLabel16.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel16.setMaximumSize(new java.awt.Dimension(0, 25));
        jLabel16.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel39.add(jLabel16);

        jPanel44.setBackground(new java.awt.Color(237, 237, 237));
        jPanel44.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel44.setLayout(new java.awt.BorderLayout());

        jTextField_annotationClassnames.setFont(new java.awt.Font("Calibri", 0, 13));
        jTextField_annotationClassnames.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jTextField_annotationClassnames.setEnabled(false);
        jTextField_annotationClassnames.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel44.add(jTextField_annotationClassnames, java.awt.BorderLayout.CENTER);

        jButton_SelectClass.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/instancewatch.png"))); // NOI18N
        jButton_SelectClass.setToolTipText("Change category of current annotation.");
        jButton_SelectClass.setFocusable(false);
        jButton_SelectClass.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton_SelectClass.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButton_SelectClass.setMinimumSize(new java.awt.Dimension(0, 0));
        jButton_SelectClass.setPreferredSize(new java.awt.Dimension(20, 20));
        jPanel44.add(jButton_SelectClass, java.awt.BorderLayout.EAST);

        jPanel39.add(jPanel44);

        jLabel38.setBackground(new java.awt.Color(236, 233, 216));
        jLabel38.setFont(new java.awt.Font("Calibri", 0, 13));
        jLabel38.setForeground(new java.awt.Color(153, 153, 153));
        jLabel38.setText("Annotation Comment:");
        jLabel38.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel38.setMaximumSize(new java.awt.Dimension(0, 25));
        jLabel38.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel39.add(jLabel38);

        jPanel55.add(jPanel39, java.awt.BorderLayout.CENTER);

        jPanel65.add(jPanel55, java.awt.BorderLayout.NORTH);

        jPanel66.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(240, 240, 240), 2));
        jPanel66.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel66.setLayout(new java.awt.BorderLayout());

        jScrollPane2.setBorder(null);
        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        jScrollPane2.setViewportBorder(javax.swing.BorderFactory.createEtchedBorder());
        jScrollPane2.setMinimumSize(new java.awt.Dimension(0, 0));

        jTextArea_comment.setBackground(new java.awt.Color(240, 240, 240));
        jTextArea_comment.setColumns(20);
        jTextArea_comment.setEditable(false);
        jTextArea_comment.setFont(new java.awt.Font("Calibri", 0, 13));
        jTextArea_comment.setLineWrap(true);
        jTextArea_comment.setRows(5);
        jTextArea_comment.setBorder(null);
        jTextArea_comment.setDisabledTextColor(new java.awt.Color(0, 1, 0));
        jTextArea_comment.setMinimumSize(new java.awt.Dimension(0, 0));
        jScrollPane2.setViewportView(jTextArea_comment);

        jPanel66.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        jPanel65.add(jPanel66, java.awt.BorderLayout.CENTER);

        jPanel_annotation_details.add(jPanel65, java.awt.BorderLayout.CENTER);

        jPanel41.add(jPanel_annotation_details);

        jPanel40.add(jPanel41, java.awt.BorderLayout.CENTER);

        add(jPanel40, java.awt.BorderLayout.NORTH);

        jSplitPane5.setBackground(new java.awt.Color(237, 237, 237));
        jSplitPane5.setDividerLocation(150);
        jSplitPane5.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane5.setResizeWeight(0.5);
        jSplitPane5.setMinimumSize(new java.awt.Dimension(0, 0));

        jPanel48.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(240, 240, 240), 2));
        jPanel48.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel48.setPreferredSize(new java.awt.Dimension(439, 200));
        jPanel48.setLayout(new java.awt.GridLayout(2, 0, 0, 2));

        jPanel70.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel70.setLayout(new java.awt.BorderLayout());

        jPanel61.setBackground(new java.awt.Color(237, 237, 237));
        jPanel61.setLayout(new java.awt.BorderLayout());

        jButton_relationships.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/instancewatch.png"))); // NOI18N
        jButton_relationships.setFocusable(false);
        jButton_relationships.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton_relationships.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButton_relationships.setMinimumSize(new java.awt.Dimension(0, 0));
        jButton_relationships.setPreferredSize(new java.awt.Dimension(20, 20));
        jPanel61.add(jButton_relationships, java.awt.BorderLayout.EAST);

        jLabel39.setBackground(new java.awt.Color(237, 237, 237));
        jLabel39.setFont(new java.awt.Font("Calibri", 0, 11));
        jLabel39.setForeground(new java.awt.Color(153, 153, 153));
        jLabel39.setText("Relationships:");
        jLabel39.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel39.setFocusable(false);
        jLabel39.setMaximumSize(new java.awt.Dimension(0, 25));
        jLabel39.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel61.add(jLabel39, java.awt.BorderLayout.CENTER);

        jPanel70.add(jPanel61, java.awt.BorderLayout.NORTH);

        jScrollPane8.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane8.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane8.setMinimumSize(new java.awt.Dimension(0, 0));

        jList_complexrelationships.setFont(new java.awt.Font("Calibri", 0, 11));
        jScrollPane8.setViewportView(jList_complexrelationships);

        jPanel70.add(jScrollPane8, java.awt.BorderLayout.CENTER);

        jPanel48.add(jPanel70);

        jPanel71.setBackground(new java.awt.Color(237, 237, 237));
        jPanel71.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel71.setLayout(new java.awt.BorderLayout());

        jScrollPane9.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane9.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane9.setMinimumSize(new java.awt.Dimension(0, 0));

        jList_normalrelationship.setFont(new java.awt.Font("Calibri", 0, 11));
        jScrollPane9.setViewportView(jList_normalrelationship);

        jPanel71.add(jScrollPane9, java.awt.BorderLayout.CENTER);

        jPanel63.setBackground(new java.awt.Color(237, 237, 237));
        jPanel63.setLayout(new java.awt.BorderLayout());

        jButton_relationships1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/res/instancewatch.png"))); // NOI18N
        jButton_relationships1.setFocusable(false);
        jButton_relationships1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton_relationships1.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButton_relationships1.setMinimumSize(new java.awt.Dimension(0, 0));
        jButton_relationships1.setPreferredSize(new java.awt.Dimension(20, 20));
        jPanel63.add(jButton_relationships1, java.awt.BorderLayout.EAST);

        jLabel40.setBackground(new java.awt.Color(237, 237, 237));
        jLabel40.setFont(new java.awt.Font("Calibri", 0, 11));
        jLabel40.setForeground(new java.awt.Color(153, 153, 153));
        jLabel40.setText("Attributes:");
        jLabel40.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel40.setFocusable(false);
        jLabel40.setMaximumSize(new java.awt.Dimension(0, 25));
        jLabel40.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel63.add(jLabel40, java.awt.BorderLayout.CENTER);

        jPanel71.add(jPanel63, java.awt.BorderLayout.NORTH);

        jPanel48.add(jPanel71);

        jSplitPane5.setLeftComponent(jPanel48);

        jPanel75.setLayout(new java.awt.BorderLayout());

        jPanel76.setBackground(new java.awt.Color(237, 237, 237));
        jPanel76.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel76.setLayout(new java.awt.GridLayout(2, 2, 2, 2));

        jLabel37.setBackground(new java.awt.Color(237, 237, 237));
        jLabel37.setFont(new java.awt.Font("Calibri", 0, 11));
        jLabel37.setForeground(new java.awt.Color(153, 153, 153));
        jLabel37.setText("Creation Date");
        jLabel37.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel37.setMaximumSize(new java.awt.Dimension(0, 16));
        jLabel37.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel76.add(jLabel37);

        jLabel33.setBackground(new java.awt.Color(236, 233, 216));
        jLabel33.setFont(new java.awt.Font("Calibri", 0, 11));
        jLabel33.setForeground(new java.awt.Color(153, 153, 153));
        jLabel33.setText("Annotator");
        jLabel33.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel33.setMaximumSize(new java.awt.Dimension(0, 16));
        jLabel33.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel76.add(jLabel33);

        jTextField_creationdate.setFont(new java.awt.Font("Calibri", 0, 11));
        jTextField_creationdate.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jTextField_creationdate.setMaximumSize(new java.awt.Dimension(0, 16));
        jTextField_creationdate.setMinimumSize(new java.awt.Dimension(0, 0));
        jTextField_creationdate.setPreferredSize(null);
        jPanel76.add(jTextField_creationdate);

        jTextField_annotator.setFont(new java.awt.Font("Calibri", 0, 11));
        jTextField_annotator.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jTextField_annotator.setMaximumSize(new java.awt.Dimension(0, 16));
        jTextField_annotator.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel76.add(jTextField_annotator);

        jPanel75.add(jPanel76, java.awt.BorderLayout.NORTH);

        jPanel87.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel87.setLayout(new java.awt.BorderLayout());

        jPanel84.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel84.setLayout(new java.awt.GridLayout(1, 2, 2, 0));

        jPanel68.setBackground(new java.awt.Color(237, 237, 237));
        jPanel68.setLayout(new java.awt.BorderLayout());

        jPanel_colorfulTextBar_filebrowser4.setBackground(new java.awt.Color(41, 119, 167));
        jPanel_colorfulTextBar_filebrowser4.setLayout(new java.awt.BorderLayout());
        jPanel68.add(jPanel_colorfulTextBar_filebrowser4, java.awt.BorderLayout.NORTH);

        jPanel69.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel69.setLayout(new java.awt.GridLayout(1, 0, 4, 4));
        jPanel68.add(jPanel69, java.awt.BorderLayout.SOUTH);

        jPanel84.add(jPanel68);

        jPanel72.setBackground(new java.awt.Color(237, 237, 237));
        jPanel72.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(240, 240, 240), 2));
        jPanel72.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel72.setLayout(new java.awt.BorderLayout());

        jLabel41.setBackground(new java.awt.Color(236, 233, 216));
        jLabel41.setFont(new java.awt.Font("Calibri", 0, 11));
        jLabel41.setForeground(new java.awt.Color(153, 153, 153));
        jLabel41.setText("Saved Verify Suggestion:");
        jLabel41.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jLabel41.setMaximumSize(new java.awt.Dimension(0, 25));
        jLabel41.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel72.add(jLabel41, java.awt.BorderLayout.NORTH);

        jScrollPane10.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane10.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane10.setMinimumSize(new java.awt.Dimension(0, 0));

        jList3.setFont(new java.awt.Font("Calibri", 0, 11));
        jScrollPane10.setViewportView(jList3);

        jPanel72.add(jScrollPane10, java.awt.BorderLayout.CENTER);

        jPanel84.add(jPanel72);

        jPanel87.add(jPanel84, java.awt.BorderLayout.CENTER);

        jPanel_colorfulTextBar_filebrowser7.setBackground(new java.awt.Color(41, 119, 167));
        jPanel_colorfulTextBar_filebrowser7.setLayout(new java.awt.BorderLayout());
        jPanel87.add(jPanel_colorfulTextBar_filebrowser7, java.awt.BorderLayout.NORTH);

        jPanel75.add(jPanel87, java.awt.BorderLayout.CENTER);

        jSplitPane5.setRightComponent(jPanel75);

        add(jSplitPane5, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents

    /**In mode of comparing difference between annotations, all annotations,
     * except the primary annotation (Depot.SelectedAnnotationSet
     * .ui_objectAnnotation), need to be showed in the comparator panel 
     * for comparing. 
     */
    public void display_showAlternativeAnnotations(){

        // ##1## empty the list
        clearlist(this.jList_selectedAnnotations);
        
        int uniqueid_of_primiaryAnnotation
                = Depot.SelectedAnnotationSet.ui_objectAnnotation;
        //if (uniqueid_of_primiaryAnnotation <0)
        //    return;
        boolean foundfirstAnnotation = false;
        try{
            

            // ##2## load annotations into this list
            
            // get stored selected annotaions
            Vector<Integer> uqids = Depot.SelectedAnnotationSet.getSelectedAnnotationSet();
            if ((uqids==null)||(uqids.size()<1))
                return;
            
            String textsourcefilename = ResultEditor.WorkSpace.WorkSet.getCurrentFile().getName();


            // ##2## Get indexes of selected annotations to this mouse position in
            // current text source
            Vector<Integer> selectedAnnotationIndexes = Depot.SelectedAnnotationSet.getSelectedAnnotationSet();
            if( selectedAnnotationIndexes == null )
                return;

            Depot depot = new Depot();

            // assemble vector v for show return results in list
            Vector<Object> listentry = new Vector<Object>();
            int size = selectedAnnotationIndexes.size();


            for( int i=0; i<size; i++ ) {

                int this_uniqueindex = selectedAnnotationIndexes.get(i);

                ResultEditor.Annotations.Annotation annotation = depot.getAnnotationByUnique( textsourcefilename, this_uniqueindex );
                if(annotation == null || !annotation.visible)
                    continue;

                // ignore the primiary annotation which already shoed on
                // editor panel
                if(annotation.uniqueIndex==uniqueid_of_primiaryAnnotation)
                    continue;

                // record current annotation to indicator current annotation
                //ResultEditor.WorkSpace.WorkSet.currentAnnotation = annotation;
                // get term information from query results                

                Color categorycolor = ResultEditor.AnnotationClasses.Depot.getColor( annotation.annotationclass );
                iListEntry le;
                le = new iListEntry( annotation , categorycolor, null );
                listentry.add( le );

                
                // Notice: most of time, we show the annotation(whose i euqal 0)
                //         but if the primiary annotation is on the first postiion
                //         of the vector, we may lost information if we still try
                //         to get the first annotation;
                if(!foundfirstAnnotation){
                    display_showAnnotationDetails(annotation);
                    foundfirstAnnotation = true;

                    // check differences between primary annotation and this
                    // annotation
                    checkDifferences(annotation);
                    display_setRedRectangle_toMarkDifferences();
                    gui.display_setRedRectangle_toMarkDifferences(
                            flags_of_differences.isDifference_inSpan,
                            flags_of_differences.isDifference_inClass,
                            flags_of_differences.isDifference_inComment,
                            flags_of_differences.isDifference_inAnnotator,
                            flags_of_differences.isDifference_inComplexRelationship,
                            flags_of_differences.isDifference_inNormalRelationship
                            );
                    
                }
            }


            // show data of selected annotations on list and set selected item
            this.jList_selectedAnnotations.setListData(listentry);
            this.jList_selectedAnnotations.setListData( listentry );
            this.jList_selectedAnnotations.setCellRenderer(new iListCellRenderer());

            this.jList_selectedAnnotations.setSelectedIndex(0);


        }catch(Exception ex){
            System.out.println("error 1011161349::fail to show annotations in " +
                    "comporator panel!!!");
        }
    }


    /**To a given annotation, show its details in correlated field
     * on this jForm.
     *
     * @param   annotation
     *          annotation whose details will be displayed on current
     *          jForm;
     */
    private void display_showAnnotationDetails(Annotation annotation){
        // ##1## empty all fields
        dispaly_emptyAllAnnotationFileds();

        // ##2## load details to field for current annotation

        if ( annotation == null )
            return;

        try{
            String location = annotation.spanstart + " | " + annotation.spanend;
            String annotator = annotation.annotator;

            jTextField_spanLocation.setText( location );
            jTextField_annotator.setText(null);
            jTextField_annotationClassnames.setText( annotation.annotationclass );

            // annotator of annotation
            if( (annotator != null )&&( annotator.trim().length() > 0) )
                jTextField_annotator.setText( annotator );
            else
                jTextField_annotator.setText(null);
        
            // create date
            if( (annotation.creationDate != null )&&( annotation.creationDate.trim().length() > 0) )
                jTextField_creationdate.setText( annotation.creationDate);
            else
                jTextField_creationdate.setText( null );

            jTextArea_comment.setText(annotation.comments);

            // textsourceFilename of current text source
            //String textsourceFilename = ResultEditor.WorkSpace.WorkSet.getCurrentFile().getName();

            // get selected annotations by mouse's positin
            ResultEditor.Annotations.Depot depot = new ResultEditor.Annotations.Depot();
            Vector<Integer> selectedAnnotationUniqueindexes = Depot.SelectedAnnotationSet.getSelectedAnnotationSet();

            int size = selectedAnnotationUniqueindexes.size();
            String textsourcefilename = ResultEditor.WorkSpace.WorkSet.getCurrentFile().getName();

        }catch(Exception ex){
            System.out.println("error 1011161459:: fail to show annotation" +
                    " details in comparator panel" + ex.toString());
        }
    }

    /**There are a lot of field on this form are used to display details of
     * designated annotation. This function can empty all contents on them.
     */
    private void dispaly_emptyAllAnnotationFileds(){
        // earse all existing data
        jTextField_spanLocation.setText(null);
        jTextField_annotationClassnames.setText(null);
        jTextArea_comment.setText(null);
        clearlist(jList_complexrelationships);
        clearlist(jList_normalrelationship);
        jTextField_creationdate.setText(null);
        jTextField_annotator.setText(null);
        clearlist(jList3);
    }

    /**Empty a designated jlist.
     *
     * @param   thislist
     *          the jList you want to empty;
     */
    private void clearlist( JList thislist){
        Vector object = new Vector();
        object.clear();
        thislist.setListData(object);
    }

    private void jTextField_spanLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField_spanLocationActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jTextField_spanLocationActionPerformed

    
    private void jList_selectedAnnotationsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList_selectedAnnotationsValueChanged
        int selected = jList_selectedAnnotations.getSelectedIndex();
        if (selected < 0) return;
        if( jList_selectedAnnotations.getModel().getSize() < 1 )
            return;
        display_showAnnotationDetails_bySequenceInList(selected);
    }//GEN-LAST:event_jList_selectedAnnotationsValueChanged


    /**while user clicked button of "accept" on comparator panel, it means we
     * will only keep this selected annotation in current stored annotation
     * set and show it as usual.
     */
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // user click accept button on comparator panel
        int selected = jList_selectedAnnotations.getSelectedIndex();
        if (selected < 0) return;
        if( jList_selectedAnnotations.getModel().getSize() < 1 )
            return;
        // ##2## transform this sequence index to unique index
        int uqid = Depot.SelectedAnnotationSet.getAnnotation_bySequenceIndex_ofComparator(selected);
        if (uqid<0)
            return;

        // user click accept button on comparator panel
        controlButton.acceptreject_acceptAlternativeAnnotation(uqid);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        try{
            int selected = jList_selectedAnnotations.getSelectedIndex();

            if (selected < 0) return;
            if( jList_selectedAnnotations.getModel().getSize() < 1 )
            return;
            // ##2## transform this sequence index to unique index
            int uqid = Depot.SelectedAnnotationSet.getAnnotation_bySequenceIndex_ofComparator(selected);
            if (uqid<0)
                return;

            // user click accept button on comparator panel
            controlButton.acceptreject_rejectAlternativeAnnotation(uqid);
        }catch(Exception ex){
            System.out.println("error 1011171423:: fail to reject annotation " +
                    "in comparator panel!!!" + ex.toString());
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    /**"ignore" is clicked on comparator panel.*/
    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        try{
            int selected = jList_selectedAnnotations.getSelectedIndex();

            if (selected < 0) return;
            if( jList_selectedAnnotations.getModel().getSize() < 1 )
            return;
            // ##2## transform this sequence index to unique index
            int uqid = Depot.SelectedAnnotationSet.getAnnotation_bySequenceIndex_ofComparator(selected);
            if (uqid<0)
                return;

            // user click "ignore" button on comparator panel
            controlButton.acceptreject_ignoreAlternativeAnnotation(uqid);
        }catch(Exception ex){
            System.out.println("error 101221402:: fail to ignore annotation " +
                    "in comparator panel!!!" + ex.toString());
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    public enum spanedittype{
        headExtendtoLeft, headShortentoRight,tailExtendtoRight,
        tailshortentoLeft, delete
    };

    
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your process code here:
        spanEdit(spanedittype.headExtendtoLeft);
}//GEN-LAST:event_jButton4ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        spanEdit(spanedittype.headShortentoRight);
}//GEN-LAST:event_jButton10ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        spanEdit(spanedittype.tailshortentoLeft);
}//GEN-LAST:event_jButton11ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your process code here:
        spanEdit(spanedittype.tailExtendtoRight);
}//GEN-LAST:event_jButton5ActionPerformed


    
    /**If you clicked any item in the annotation list on comparator, let use
     * this sequence number of you clicked annotation to approach that
     * annotation, and then show annotation details on fields of
     * comparator panel.
     *
     * @param   sequenceinList
     *          the number counted from 0, it's the index of selected item in
     *          jlist.
     */
    private void display_showAnnotationDetails_bySequenceInList(int sequenceinList){
        try{
            // ##1## earse existing contents
            dispaly_emptyAllAnnotationFileds();

            // validity check
            int max = jList_selectedAnnotations.getModel().getSize();
            if ((sequenceinList <0)||(sequenceinList > max-1))
                return;

            // ##2## transform this sequence index to unique index
            int uqid = Depot.SelectedAnnotationSet.getAnnotation_bySequenceIndex_ofComparator(sequenceinList);
            if (uqid<0)
                return;

            Depot depot = new Depot();
            String filename = ResultEditor.WorkSpace.WorkSet.getCurrentFile().getName().trim();
            Annotation anno = depot.getAnnotationByUnique(filename, uqid);
            this.display_showAnnotationDetails( anno );

            displayRelationships(anno);

            // #### check for differences between this annotation and primary
            // annotation
            checkDifferences(anno);
            display_setRedRectangle_toMarkDifferences();
            gui.display_setRedRectangle_toMarkDifferences(
                            flags_of_differences.isDifference_inSpan,
                            flags_of_differences.isDifference_inClass,
                            flags_of_differences.isDifference_inComment,
                            flags_of_differences.isDifference_inAnnotator,
                            flags_of_differences.isDifference_inComplexRelationship,
                            flags_of_differences.isDifference_inNormalRelationship
                            );
            
        }catch(Exception ex){
            System.out.println("error 1011151534::fail to show annotation " +
                    "details\n" + ex.toString());
        }
    }

    /**Use difference information stored in inner class "flags_of_differences"
     * to set the borders of corrlated components. Use red rectangles to indicate
     * difference.
     * 
     * This function only can be called after you have run function of 
     * "checkDifferences(Annotation)". 
     */
    private void display_setRedRectangle_toMarkDifferences(){
        
        // ##1## set boarder if annotation span difference found
        try{
            if (flags_of_differences.isDifference_inSpan){
                jTextField_spanLocation.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0), 2));
            }else{
                jTextField_spanLocation.setBorder(null);
            }
        }catch(Exception ex){System.out.println("error 1011162346::1");}

        // ##3## set boarder if annotation span difference found
        try{
            if (flags_of_differences.isDifference_inClass){
                jTextField_annotationClassnames.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0), 2));
            }else{
                jTextField_annotationClassnames.setBorder(null);
            }
        }catch(Exception ex){System.out.println("error 1011162346::3");}

        // ##4## set boarder if  difference found in annotation comments
        try{
            if (flags_of_differences.isDifference_inComment){
                jPanel66.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0), 2));
            }else{
                jPanel66.setBorder(null);
            }
        }catch(Exception ex){System.out.println("error 1011162346::4");}

        // ##5## set boarder if  difference found in annotator of annotations
        try{
            if (flags_of_differences.isDifference_inAnnotator){
                jTextField_annotator.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0), 2));
            }else{
                jTextField_annotator.setBorder(null);
            }
        }catch(Exception ex){System.out.println("error 1011162346::5");}


        // ##6## set boarder if  difference found in complex relationships of annotations
        try{
            if (flags_of_differences.isDifference_inComplexRelationship){
                jPanel70.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0), 2));
            }else{
                jPanel70.setBorder(null);
            }
        }catch(Exception ex){System.out.println("error 1011162346::6");}

        // ##7## set boarder if  difference found in normal relationships of annotations
        try{
            if (flags_of_differences.isDifference_inNormalRelationship){
                jPanel71.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0), 2));
            }else{
                jPanel71.setBorder(null);
            }
        }catch(Exception ex){System.out.println("error 1011162346::7");}

    }


    /**Compare primary annotation to a given annotation, try to find 
     * differences. 
     * 
     * @param   annotation
     *          the given annotation for comparing.    
     */
    private void checkDifferences(Annotation annotation){
        try{
            // ##1## reset all flags of difference in inner class of <code>
            // flags_of_differences</code>
            flags_of_differences.setAlltoFalse();

            // ##2## validity check
            if(annotation==null)
                return;
            int uniqueindex_ofPrimaryAnnotation = Depot.SelectedAnnotationSet.ui_objectAnnotation;
            if (uniqueindex_ofPrimaryAnnotation <0)
                return;
            Depot depot = new Depot();
            String filename = ResultEditor.WorkSpace.WorkSet.getCurrentFile().getName().trim();
            Annotation primaryAnnotation = depot.getAnnotationByUnique(filename, uniqueindex_ofPrimaryAnnotation);
            if (primaryAnnotation==null)
                return;

            // ##3## compare 2 annotations
            // ##3.1## compare span
            try{
                if( (annotation.spanstart != primaryAnnotation.spanstart)
                    || (annotation.spanend != primaryAnnotation.spanend) ){
                    flags_of_differences.isDifference_inSpan = true;
                }
            }catch(Exception ex){System.out.println("error 1011161704::1");}

            // ##3.2## compare annotation text
            try{
                if( (annotation.annotationText == null )&&(primaryAnnotation.annotationText!=null))
                    flags_of_differences.isDifference_inText = true;
                else if( (primaryAnnotation.annotationText==null)&&(annotation.annotationText != null ))
                    flags_of_differences.isDifference_inText = true;
                else if( annotation.annotationText.compareTo(primaryAnnotation.annotationText)!=0  )
                    flags_of_differences.isDifference_inText = true;
                
            }catch(Exception ex){System.out.println("error 1011161704::2");}

            // ##3.3## compare annotation class
            try{
                if( (annotation.annotationclass == null )&&(primaryAnnotation.annotationclass!=null))
                    flags_of_differences.isDifference_inClass = true;
                else if( (primaryAnnotation.annotationclass==null)&&(annotation.annotationclass != null ))
                    flags_of_differences.isDifference_inClass = true;
                else if( annotation.annotationclass.compareTo(primaryAnnotation.annotationclass)!=0  )
                    flags_of_differences.isDifference_inClass = true;

            }catch(Exception ex){System.out.println("error 1011161704::3");}


            // ##3.4## compare annotation comment
            try{
                if( (annotation.comments == null )&&(primaryAnnotation.comments!=null))
                    flags_of_differences.isDifference_inComment = true;
                else if( (primaryAnnotation.comments==null)&&(annotation.comments != null ))
                    flags_of_differences.isDifference_inComment = true;
                else if( annotation.comments.compareTo(primaryAnnotation.comments)!=0  )
                    flags_of_differences.isDifference_inComment = true;

            }catch(Exception ex){System.out.println("error 1011161704::4");}


            // ##3.5## compare annotator of annotations
            try{
                if( (annotation.annotator == null )&&(primaryAnnotation.annotator !=null))
                    flags_of_differences.isDifference_inAnnotator = true;
                else if( (primaryAnnotation.annotator==null)&&(annotation.annotator != null ))
                    flags_of_differences.isDifference_inAnnotator = true;
                else if( annotation.annotator.compareTo(primaryAnnotation.annotator)!=0  )
                    flags_of_differences.isDifference_inAnnotator = true;

            }catch(Exception ex){System.out.println("error 1011161704::5");}

            // ##3.6## compare complex relationships of annotations
            try{
                if( (annotation.ComplexRelationships == null )&&(primaryAnnotation.ComplexRelationships ==null))
                    flags_of_differences.isDifference_inComplexRelationship = false;
                else if( (annotation.ComplexRelationships == null )&&(primaryAnnotation.ComplexRelationships !=null)){
                    if(primaryAnnotation.ComplexRelationships.size()<1)
                        flags_of_differences.isDifference_inComplexRelationship = false;
                    else
                        flags_of_differences.isDifference_inComplexRelationship = true;
                }else if( (primaryAnnotation.ComplexRelationships==null)&&(annotation.ComplexRelationships != null )){
                    if(annotation.ComplexRelationships.size()<1)
                        flags_of_differences.isDifference_inComplexRelationship = false;
                    else
                        flags_of_differences.isDifference_inComplexRelationship = true;
                }else if( (primaryAnnotation.ComplexRelationships.size()<1)&&(annotation.ComplexRelationships.size()<1 )){
                    flags_of_differences.isDifference_inComplexRelationship = false;
                }else {
                    for(ComplexRelationship cr: annotation.ComplexRelationships){
                        if ((cr==null)||(cr.getLinkedAnnotations()==null))
                            continue;
                        for(eComplex ec : cr.getLinkedAnnotations()){
                            if ((ec==null)||(ec.linkedAnnotationIndex<=0))
                                continue;

                            // found unique index of each linked annotations
                            int linkeduniqueindex = ec.linkedAnnotationIndex;
                            boolean match=false;

                            // compare this unique index with unique id in another annotation
                            for(ComplexRelationship cr2: primaryAnnotation.ComplexRelationships){
                                if ((cr2==null)||(cr2.getLinkedAnnotations()==null))
                                    continue;
                                for(eComplex ec2 : cr2.getLinkedAnnotations()){
                                    if ((ec2==null)||(ec2.linkedAnnotationIndex<=0))
                                        continue;
                                    if (ec2.linkedAnnotationIndex == linkeduniqueindex )
                                        match = true;
                                }
                            }

                            // if could not find same unique index, difference appeared
                            if(match!=true)
                                flags_of_differences.isDifference_inComplexRelationship = true;

                        }
                    }
                }
            }catch(Exception ex){System.out.println("error 1011161704::6");}


            // ##3.7## compare normal relationships of annotations
            try{
                if( (annotation.normalrelationships == null )&&(primaryAnnotation.normalrelationships ==null))
                    flags_of_differences.isDifference_inNormalRelationship = false;
                else if( (annotation.normalrelationships == null )&&(primaryAnnotation.normalrelationships !=null)){
                    if(primaryAnnotation.normalrelationships.size()<1)
                        flags_of_differences.isDifference_inNormalRelationship = false;
                    else
                        flags_of_differences.isDifference_inNormalRelationship = true;
                }else if( (primaryAnnotation.normalrelationships==null)&&(annotation.normalrelationships != null )){
                    if(annotation.normalrelationships.size()<1)
                        flags_of_differences.isDifference_inNormalRelationship = false;
                    else
                        flags_of_differences.isDifference_inNormalRelationship = true;
                }else if( (annotation.normalrelationships.size()<1 )&&(primaryAnnotation.normalrelationships.size()<1)){
                    flags_of_differences.isDifference_inNormalRelationship = false;
                }else {
                    flags_of_differences.isDifference_inNormalRelationship = false;
                    for(NormalRelationship nr: annotation.normalrelationships){

                        if (flags_of_differences.isDifference_inNormalRelationship == true)
                            break;

                        if ((nr==null)||(nr.relationshipName==null))
                            continue;
                        if(nr.relationshipName.trim().length()<1)
                            continue;                        
                        // get each relationship name
                        String relationshipname=nr.relationshipName.trim();
                        // get each value to this name
                        Vector<String> relationshipValues = nr.relationshipValue;

                        boolean match_name=false;
                        
                        for(NormalRelationship nr2: primaryAnnotation.normalrelationships){
                            
                            if (flags_of_differences.isDifference_inNormalRelationship == true)
                                break;

                            if ((nr2==null)||(nr2.relationshipName==null))
                                continue;
                            if(nr2.relationshipName.trim().length()<1)
                                continue;

                            String relationshipname2 = nr2.relationshipName.trim();
                            Vector<String> relationshipValues2 = nr2.relationshipValue;

                            // #### compare values if name are same
                            if( relationshipname.compareTo(relationshipname2)==0){
                                
                                boolean match_value=false;
                                match_name = true;

                                if((relationshipValues==null)&&(relationshipValues2==null))
                                    match_value = true;
                                else if((relationshipValues==null)&&(relationshipValues2.size()<1))
                                    match_value = true;
                                else if((relationshipValues.size()<1)&&(relationshipValues2==null))
                                    match_value = true;
                                else if((relationshipValues.size()<1)&&(relationshipValues2.size()<1))
                                    match_value = true;
                                else {
                                    for(String str1:relationshipValues){
                                        if(str1==null) str1="";
                                        for(String str2:relationshipValues2){
                                            if(str2==null)  str2="";
                                            if(str1.trim().compareTo(str2.trim())==0)
                                                match_value = true;
                                        }
                                    }
                                }

                                if(!match_value){
                                    flags_of_differences.isDifference_inNormalRelationship = true;
                                }
                            }

                        }                       
                        // if could not find same unique index, difference appeared
                        if(!match_name){
                            flags_of_differences.isDifference_inNormalRelationship = true;
                        }

                        
                    }
                }
            }catch(Exception ex){System.out.println("error 1011161704::7");}

        }catch(Exception ex){
            System.out.println("error ");
        }
    }

    
    /** display normalrelationships information of current annotation*/
    private void displayRelationships( final ResultEditor.Annotations.Annotation annotation ) {

        //####-1-   show normal relationships
        if ( annotation.normalrelationships == null ){
            Vector empty = new Vector();
            jList_normalrelationship.setListData(empty);
            //jLabel_typeOfRelationship.setText("Type of normalrelationships: ");
        } else {
            //jLabel_typeOfRelationship.setText("Type of normalrelationships: ");
            Vector<String> list = new Vector<String>();
            for( ResultEditor.Annotations.NormalRelationship normalrelationship : annotation.normalrelationships ){
                if (normalrelationship == null) continue;
                for(String stringslotvalue: normalrelationship.relationshipValue){
                    String str;
                    if( stringslotvalue != null ) {
                        str = " \"" + normalrelationship.relationshipName + "\" = " + stringslotvalue;
                    } else {
                        str = " \"" + normalrelationship.relationshipName + "\"";
                    }
                    list.add(str);
                }
            }
            jList_normalrelationship.setListData( list );
        }


        //####-2-   show complex relationships
        if ( annotation.ComplexRelationships == null ){
            Vector cempty = new Vector();
            jList_complexrelationships.setListData(cempty);
        } else {
            //jLabel_typeOfRelationship.setText("Type of normalrelationships: ");
            Vector<String> clist = new Vector<String>();
            for( ResultEditor.Annotations.ComplexRelationship relationship : annotation.ComplexRelationships ){
                if (relationship == null) continue;
                for(ResultEditor.Annotations.eComplex linkedannotationtext : relationship.getLinkedAnnotations() ){
                    String str = " \"" + relationship.getMentionSlotID() + "\" = " + linkedannotationtext.linkedAnnotationText ;
                    clist.add(str);
                }
            }
            jList_complexrelationships.setListData( clist );
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton_SelectClass;
    private javax.swing.JButton jButton_relationships;
    private javax.swing.JButton jButton_relationships1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel_toolbar_split;
    private javax.swing.JList jList3;
    private javax.swing.JList jList_complexrelationships;
    private javax.swing.JList jList_normalrelationship;
    private javax.swing.JList jList_selectedAnnotations;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel39;
    private javax.swing.JPanel jPanel40;
    private javax.swing.JPanel jPanel41;
    private javax.swing.JPanel jPanel42;
    private javax.swing.JPanel jPanel43;
    private javax.swing.JPanel jPanel44;
    private javax.swing.JPanel jPanel45;
    private javax.swing.JPanel jPanel48;
    private javax.swing.JPanel jPanel50;
    private javax.swing.JPanel jPanel55;
    private javax.swing.JPanel jPanel61;
    private javax.swing.JPanel jPanel63;
    private javax.swing.JPanel jPanel64;
    private javax.swing.JPanel jPanel65;
    private javax.swing.JPanel jPanel66;
    private javax.swing.JPanel jPanel68;
    private javax.swing.JPanel jPanel69;
    private javax.swing.JPanel jPanel70;
    private javax.swing.JPanel jPanel71;
    private javax.swing.JPanel jPanel72;
    private javax.swing.JPanel jPanel74;
    private javax.swing.JPanel jPanel75;
    private javax.swing.JPanel jPanel76;
    private javax.swing.JPanel jPanel84;
    private javax.swing.JPanel jPanel87;
    private javax.swing.JPanel jPanel_annotation_details;
    private javax.swing.JPanel jPanel_colorfulTextBar_filebrowser3;
    private javax.swing.JPanel jPanel_colorfulTextBar_filebrowser4;
    private javax.swing.JPanel jPanel_colorfulTextBar_filebrowser7;
    private javax.swing.JPanel jPanel_multipleResultShowList;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JSplitPane jSplitPane5;
    private javax.swing.JTextArea jTextArea_comment;
    private javax.swing.JTextField jTextField_annotationClassnames;
    private javax.swing.JTextField jTextField_annotator;
    private javax.swing.JTextField jTextField_creationdate;
    private javax.swing.JTextField jTextField_spanLocation;
    private javax.swing.JToolBar jToolBar4;
    private javax.swing.JToolBar jToolBar5;
    // End of variables declaration//GEN-END:variables

    /**edit span of annotation current selected on comparator panel*/
    public void spanEdit(spanedittype _type)
    {
        int sequenceinList  = -1;
        int annotation_uid = -1;
        // ##1##
        // try to get current selected annotation on comparator panel
        try{
            sequenceinList  = jList_selectedAnnotations.getSelectedIndex();
            
            if (sequenceinList  < 0)
                return;
            if( jList_selectedAnnotations.getModel().getSize() < 1 )
                return;

            // validity check
            int max = jList_selectedAnnotations.getModel().getSize();
            if ((sequenceinList <0)||(sequenceinList > max-1))
                return;

            // ##2## transform this sequence index to unique index
            annotation_uid = Depot.SelectedAnnotationSet.getAnnotation_bySequenceIndex_ofComparator(sequenceinList);
            //System.out.println("uid="+annotation_uid);
            if (annotation_uid <0)
                return;

        }catch(Exception ex){
            System.out.println("error 1012011539:: fail to find alternative annotation!");
        }

        //##2## call function to do real span modification
        try{
            String textsourcefilename = ResultEditor.WorkSpace.WorkSet.getCurrentFile().getName();

            ResultEditor.SpanEdit.SpanEditor spanEditor  =
                new ResultEditor.SpanEdit.SpanEditor(textPaneforClinicalNotes);
            int delete = 0, headdecrease = 1, tailincrease = 2,
                    headincrease = 3, taildecrease =4;

            switch(_type){

                case headExtendtoLeft:
                     spanEditor.editCurrentDisplayedSpan(textsourcefilename, annotation_uid, headdecrease);
                    break;

                case tailExtendtoRight:
                    spanEditor.editCurrentDisplayedSpan(textsourcefilename, annotation_uid, tailincrease);
                    break;

                case headShortentoRight:
                    spanEditor.editCurrentDisplayedSpan(textsourcefilename, annotation_uid, headincrease);
                    break;

                case tailshortentoLeft:
                    spanEditor.editCurrentDisplayedSpan(textsourcefilename, annotation_uid, taildecrease);                    
                    break;
            }

            // show details to the modificated annotation
            display_showAnnotationDetails_bySequenceInList(sequenceinList);

            this.display_showAlternativeAnnotations();
            this.jList_selectedAnnotations.setSelectedIndex(sequenceinList);

            gui.repaintHighlighter();
        
        }catch(Exception ex){
            System.out.println("error 1012011438:: fail to refresh screen after " +
                    "span modified!!!");
        }

    }
}
